/*
 *    This file is part of CeluMap.
 *
 *    CeluMap is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CeluMap is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    Copyright 2006, 2007, 2008 Gonzalo Merayo
 *    gonzalo (at) celumap.com.ar
 *    www.celumap.com.ar
 *
 */

package figures.basic;

import geometry.Matrix;
import geometry.MovingTransform;
import geometry.Point;
import geometry.Rectangle;
import screen.GisGraphics;

import map.file.FileConstants;

public class Poligon extends PoliLine {
	
	public Poligon(Point[] p, String name){
		super(p, name);
	}
	public Poligon(NameManager n){
		super(n);
	}
	
	public Poligon() {
		super();
	}
	public byte getFillColor(){
		return 0;
	}
	
	public void drawIn(GisGraphics g, Rectangle area, MovingTransform transform) {
		if(getFillColor() != 0xFF000000)
			fill(g, area, transform);
		if(getColor() != 0xFF000000){
			drawInAsPoliline(g, area, transform);
		}
	}
	
	static int[] sx,sy;
	private void fill(GisGraphics arg0, Rectangle area, MovingTransform transform) {
		arg0.setColor(getFillColor());
		if(sx == null || sx.length<(l+1)){
			sx = new int[1+l];
			sy = new int[1+l];
		}
		sx[0] = transform.mapX2screen(ix,iy);
		sy[0] = transform.mapY2screen(ix,iy);
		long z = transform.getZoom();
		int ox = 0;
		int oy = 0;
		for(int i=0;i<l;i++){
			ox += nm.buffer[offsetinit+i];
			oy += nm.buffer[offsetinit+i+l];
			sx[i+1] = sx[0]+ (int)((z*ox)>>Matrix.nshift);
			sy[i+1] = sy[0]+ (int)((z*oy)>>Matrix.nshift);
		}
		arg0.fill(sx, sy, 1+l);
	}
	
	public byte getType() {
		return FileConstants.FIG_TYPE_PGON;
	}
	public void drawInAsPoliline(GisGraphics g, Rectangle area, MovingTransform t) {
		super.drawIn(g, area, t);
		if(area.colides(x1, y1, x0, y0))
			g.drawLine(x1, y1, x0, y0);
	}
	public void drawVolatileIn(GisGraphics g, Rectangle area, MovingTransform transform, boolean highlight, int frame) {
		g.drawString(getName(), transform.mapX2screen(bbxi, ycenter()),transform.mapY2screen(bbxi, ycenter()), 1, 0);
	}
	

}
